package cn.rengy.web.framework.wxmp.miniprogram;

import cn.rengy.lang.ResultEntity;
import cn.rengy.tpa.wxmp.miniprogram.phonenumber.entity.PhoneInfoResponse;
import cn.rengy.tpa.wxmp.miniprogram.phonenumber.PhoneNumberApi;
import cn.rengy.tpa.wxmp.token.AccessToken;
import cn.rengy.web.framework.wxmp.token.AccessTokenCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PhoneNumberService {
    @Autowired
    private AccessTokenCacheService accessTokenCacheService;

    public ResultEntity<?,String> getPhoneNumber(GetPhoneNumberVO getPhoneNumberVO){
        String appid= getPhoneNumberVO.getAppid();
        String code= getPhoneNumberVO.getCode();
        AccessToken accessToken=accessTokenCacheService.getAccessToken(appid);
        PhoneInfoResponse phoneInfoResponse=PhoneNumberApi.getPhoneNumber(accessToken,code);
        return ResultEntity.ok(phoneInfoResponse.getPurePhoneNumber());
    }

}
